from django.http import HttpResponse
from django.shortcuts import render
from django.utils.decorators import method_decorator
from django.views import View
from django.views.decorators.csrf import csrf_protect, csrf_exempt
from django.views.generic import TemplateView


@csrf_exempt
def view1(request):
    name = 'view1'
    if request.method == 'GET':
        return HttpResponse(f'get on {name}')
    else:
        return HttpResponse(f'post on {name}')


class GetMiXin:
    def get(self, request, *args, **kwargs):
        return HttpResponse(f'get on {self.name}')


class PostMiXin:
    def post(self, request, *args, **kwargs):
        return HttpResponse(f'post on {self.name}')


@method_decorator(csrf_exempt, name='dispatch')
class View2(GetMiXin, PostMiXin, View):
    name = 'view2'

    # @method_decorator(csrf_exempt)
    # def dispatch(self, request, *args, **kwargs):
    #     return super(View2, self).dispatch(request, *args, **kwargs)


def about1(request):
    return render(request, 'class/about.html')


# 混入 实际就是python的多重继承
# 继承的类里面 只有一个是来自于View，要不然会导致你的混乱

class About3(TemplateView):
    template_name = 'class/about.html'
